package cn.sw.system.onemany.agg.zhujie;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class QueryWrapper {
    private List<Condition> conditions = new ArrayList<>();

    public static class Condition {
        String column;
        Operator operator;
        Object value;

        public Condition(String column, Operator operator, Object value) {
            this.column = column;
            this.operator = operator;
            this.value = value;
        }

        public String toSQL() {
            switch (operator) {
                case EQ: return column + " = ?";
                case NE: return column + " <> ?";
                case LIKE: return column + " LIKE ?";
                case GT: return column + " > ?";
                case LT: return column + " < ?";
                case IN: return column + " IN (${value})".replace("${value}", value.toString());
                case IS_NULL: return column + " IS NULL";
                case NOT_NULL: return column + " IS NOT NULL";
                default: throw new IllegalArgumentException("Unsupported operator");
            }
        }
    }

    public String buildWhereClause() {
        if (conditions.isEmpty()) return "";
        return " WHERE " + conditions.stream()
                .map(Condition::toSQL)
                .collect(Collectors.joining(" AND "));
    }
}
